*** Top 10 Lists for only men income, and household earnings.

* For both men income statistics and household earnings:
foreach var in men household {

* Load robustness check data and merge on counts from main data (to keep sample
* constant)
use "$robustness", clear
merge 1:1 super using "$college_collapse", keepusing(count) 
rename count count_main

* Keep only if we have data.
if "`var'" == "men"        {
	keep if ~mi(count_m)
	rename *_m *
}
if "`var'" == "household" {
	keep if ~mi(count_wagse_hh)
	rename *_wagse_hh *
}

* Combine CUNYs into 1 (be careful to weight success rate by par_q1 * count)
preserve
keep if inlist(super,7273,2688,7022,2693,2696,2687,2689,2690,4759,8611,2691,10051,2692,2697,10097,2694,2698)
egen temp = wtmean(mr_kq5_pq1), weight(par_q1*count)
replace mr_kq5_pq1 = temp
collapse (mean) mr_kq5_pq1 kq5_cond_parq1 par_q1 (rawsum) count [w=count]
gen super = 9999
gen name = "CUNY System"
tempfile temp
save `temp'

* Drop individual CUNYs and append the CUNY System data
restore
drop if inlist(super,7273,2688,7022,2693,2696,2687,2689,2690,4759,8611,2691,10051,2692,2697,10097,2694,2698)
append using `temp'

* Export
foreach v of varlist mr_kq5_pq1 par_q1 kq5_cond_parq1 {
	replace `v' = `v'*100
}

* DROP CLOSED SUPERS FROM APPX TAB XXII
cap drop _merge
merge 1:1 super_opeid using $closed_supers, keepusing(super_opeid)
drop if _merge == 3 | _merge == 2
drop _merge

gsort -mr_kq5_pq1
preserve
keep if count_main >= 300
keep if _n <= 10
keep name mr_kq5_pq1 par_q1 kq5_cond_parq1 
list
if "`var'" == "men"       export delimited using "${tabs}/app_table21a.csv", replace
if "`var'" == "household" export delimited using "${tabs}/app_table21b.csv", replace

restore
}

